package softtech.apps.adapter;

import java.util.ArrayList;
import java.util.List;

import softtech.apps.adapter.UserListAdapter.UserViewHolder;
import softtech.apps.dangtinraovat.R;
import softtech.apps.model.Product;
import softtech.apps.model.User;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ProductEndlessAdapter extends ArrayAdapter<Product>{
	private static final String TAG = "ProductArrayAdapter";
	private List<Product> productList = new ArrayList<Product>();
	private Context mContext;
	private int layoutId;
    static class UserViewHolder {
        ImageView productThumbnail;
        TextView productName;
        TextView timeCreate;
    }
    
	public ProductEndlessAdapter(Context context,List<Product> lst, int layoutId) {
		// TODO Auto-generated constructor stub
		super(context, layoutId, lst);
		mContext = context;
		productList = lst;
		this.layoutId = layoutId;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.productList.size();
	}

	@Override
	public Product getItem(int position) {
		// TODO Auto-generated method stub
		return this.productList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return this.productList.get(position).hashCode();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View row = convertView;
		if (row == null) {
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(layoutId, parent, false);
		}
//		UserViewHolder viewHolder;
//		if (row == null) {
//			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//			row = inflater.inflate(layoutId, parent, false);
//            viewHolder = new UserViewHolder();
//            viewHolder.productThumbnail = (ImageView) row.findViewById(R.id.imgProductThumbnail);
//            viewHolder.productName = (TextView) row.findViewById(R.id.tvProductName);
//            viewHolder.timeCreate = (TextView) row.findViewById(R.id.tvTimeCreate);
//            row.setTag(viewHolder);
//		} else {
//            viewHolder = (UserViewHolder)row.getTag();
//        }
		Product product = getItem(position);
		// Set lai avatar cho user
		ImageView productThumbnail = (ImageView) row.findViewById(R.id.imgProductThumbnail);
		TextView productName = (TextView) row.findViewById(R.id.tvProductName);
		TextView timeCreate = (TextView) row.findViewById(R.id.tvTimeCreate);
        productThumbnail.setImageResource(R.drawable.ic_launcher);
        productName.setText(product.getpName());
        timeCreate.setText(product.getpTimeCreate());
		return row;
	}
	
}
